//
//  AuthTableViewCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/4/26.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
import UIKit
class AuthTableViewCell:UITableViewCell{
    var checkState: UILabel!
    var realNameText,codeText,referralText:UITextField!
    var btn1,btn2,btn3,btn4,submitBtn:UIButton!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.layer.borderWidth = 0
        self.setupMainView()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupMainView() {
        let acv = AuthViewController()
        // 背景view
        let backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenW, height:sd_height))
        self.addSubview(backgroundView)
        backgroundView.snp.makeConstraints { (make) in
            make.left.equalTo(self)
            make.top.equalTo(self)
            make.right.equalTo(self)
            make.bottom.equalTo(self)
        }
        let isCheck = UILabel()
        isCheck.font = UIFont.systemFont(ofSize: 14)
        isCheck.text = "是否验证"
        backgroundView.addSubview(isCheck)
        isCheck.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(backgroundView.snp.top).offset(5)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(oLabelW)
        }
        checkState = UILabel()
        checkState.font = UIFont.systemFont(ofSize: 12)
        checkState.textColor = UIColor.red
        backgroundView.addSubview(checkState)
        checkState.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(backgroundView.snp.top)
            make.right.equalTo(self).offset(-10)
            make.width.equalTo(75)
        }
        //粗分割线
        let Bseparator = UILabel()
        Bseparator.backgroundColor = tableBgColor
        backgroundView.addSubview(Bseparator)
        Bseparator.snp.makeConstraints { (make) in
            make.height.equalTo(10)
            make.top.equalTo(isCheck.snp.bottom)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        let realName = UILabel()
        realName.font = UIFont.systemFont(ofSize: 14)
        realName.text = "真实姓名"
        backgroundView.addSubview(realName)
        realName.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(Bseparator.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(isCheck.snp.width)
        }
        realNameText = UITextField()
        realNameText.textColor = fontColor
        realNameText.font = UIFont.systemFont(ofSize: 14)
        realNameText.clearButtonMode = .whileEditing
        realNameText.autocapitalizationType = .none //关闭首字母自动大写
        backgroundView.addSubview(realNameText)
        realNameText.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.width.equalTo(kScreenW - 90)
            make.top.equalTo(Bseparator.snp.bottom)
            make.left.equalTo(realName.snp.right)
        }
        //细分割线
        let bseparator1 = UILabel()
        bseparator1.backgroundColor = tableBgColor
        backgroundView.addSubview(bseparator1)
        bseparator1.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(realName.snp.bottom)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        
        let referralLabel = UILabel()
        referralLabel.font = UIFont.systemFont(ofSize: 14)
        referralLabel.text = "推荐人"
        backgroundView.addSubview(referralLabel)
        referralLabel.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(bseparator1.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(isCheck.snp.width)
        }
        referralText = UITextField()
        referralText.textColor = fontColor
        referralText.font = UIFont.systemFont(ofSize: 14)
        referralText.clearButtonMode = .whileEditing
        backgroundView.addSubview(referralText)
        referralText.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.width.equalTo(kScreenW - 90)
            make.top.equalTo(bseparator1.snp.bottom)
            make.left.equalTo(referralLabel.snp.right)
        }
        //细分割线
        let bseparator5 = UILabel()
        bseparator5.backgroundColor = tableBgColor
        backgroundView.addSubview(bseparator5)
        bseparator5.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(referralLabel.snp.bottom)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        
        let codeTyle = UILabel()
        codeTyle.font = UIFont.systemFont(ofSize: 14)
        codeTyle.text = "证件类型"
        backgroundView.addSubview(codeTyle)
        codeTyle.snp.makeConstraints { (make) in
            make.height.equalTo(40)
            make.top.equalTo(bseparator5.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(isCheck.snp.width)
        }
        let codeTyle2 = UILabel()
        codeTyle2.textColor = fontColor
        codeTyle2.font = UIFont.systemFont(ofSize: 14)
        codeTyle2.text = "身份证"
        backgroundView.addSubview(codeTyle2)
        codeTyle2.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(bseparator5.snp.bottom)
            make.left.equalTo(codeTyle.snp.right)
            make.width.equalTo(isCheck.snp.width)
        }
        //细分割线
        let bseparator2 = UILabel()
        bseparator2.backgroundColor = tableBgColor
        backgroundView.addSubview(bseparator2)
        bseparator2.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(codeTyle.snp.bottom)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        let codeNum = UILabel()
        codeNum.font = UIFont.systemFont(ofSize: 14)
        codeNum.text = "证件号码"
        backgroundView.addSubview(codeNum)
        codeNum.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(bseparator2.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(isCheck.snp.width)
        }
        codeText = UITextField()
        codeText.textColor = fontColor
        codeText.font = UIFont.systemFont(ofSize: 14)
        codeText.clearButtonMode = .whileEditing
        backgroundView.addSubview(codeText)
        codeText.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.width.equalTo(kScreenW - 90)
            make.top.equalTo(bseparator2.snp.bottom)
            make.left.equalTo(codeNum.snp.right)
        }
        //细分割线
        let bseparator3 = UILabel()
        bseparator3.backgroundColor = tableBgColor
        backgroundView.addSubview(bseparator3)
        bseparator3.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.top.equalTo(codeNum.snp.bottom)
            make.left.equalTo(self)
            make.right.equalTo(self)
        }
        let codeIcon = UILabel()
        codeIcon.font = UIFont.systemFont(ofSize: 14)
        codeIcon.text = "证件照片"
        backgroundView.addSubview(codeIcon)
        codeIcon.snp.makeConstraints { (make) in
            make.height.equalTo(cellH)
            make.top.equalTo(bseparator3.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(10)
            make.width.equalTo(isCheck.snp.width)
        }
        //证件照片
        btn1 = UIButton()
        btn1.setBackgroundImage(UIImage(named:"shenfenzheng1"), for: .normal)
        btn1.tag = 1
        btn1.addTarget(acv, action: #selector(acv.choicePicture(sender:)), for: UIControlEvents.touchUpInside)
        backgroundView.addSubview(btn1)
        btn1.snp.makeConstraints { (make) in
            make.top.equalTo(bseparator3.snp.bottom).offset(10)
            make.left.equalTo(codeIcon.snp.right)
            make.height.equalTo(oImgH)
            make.width.equalTo(oImgW)
        }
        
        btn2 = UIButton()
        btn2.setBackgroundImage(UIImage(named:"shenfenzheng2"), for: .normal)
        btn2.tag = 2
        btn2.addTarget(acv, action: #selector(acv.choicePicture(sender:)), for: UIControlEvents.touchUpInside)
        backgroundView.addSubview(btn2)
        btn2.snp.makeConstraints { (make) in
            make.top.equalTo(btn1.snp.bottom).offset(10)
            make.left.equalTo(codeIcon.snp.right)
            make.height.equalTo(oImgH)
            make.width.equalTo(oImgW)
        }
        btn3 = UIButton()
        btn3.setBackgroundImage(UIImage(named:"shenfenzheng3"), for: .normal)
        btn3.tag = 3
        btn3.addTarget(acv, action: #selector(acv.choicePicture(sender:)), for: UIControlEvents.touchUpInside)
        backgroundView.addSubview(btn3)
        btn3.snp.makeConstraints { (make) in
            make.top.equalTo(btn2.snp.bottom).offset(10)
            make.left.equalTo(codeIcon.snp.right)
            make.height.equalTo(oImgH)
            make.width.equalTo(oImgW)
        }
        btn4 = UIButton()
        btn4.setBackgroundImage(UIImage(named:"shenfenzheng4"), for: .normal)
        btn4.tag = 4
        btn4.addTarget(acv, action: #selector(acv.choicePicture(sender:)), for: UIControlEvents.touchUpInside)
        backgroundView.addSubview(btn4)
        btn4.snp.makeConstraints { (make) in
            make.top.equalTo(btn3.snp.bottom).offset(10)
            make.left.equalTo(codeIcon.snp.right)
            make.height.equalTo(oImgH)
            make.width.equalTo(oImgW)
        }
        submitBtn = UIButton(type: .custom)
        submitBtn.setTitleColor(UIColor.white, for: .normal)
        submitBtn.setTitle("提交审核", for: .normal)
        submitBtn.backgroundColor = appMainColor
        submitBtn.showsTouchWhenHighlighted = true
        submitBtn.layer.cornerRadius = 5
        submitBtn.addTarget(acv, action: #selector(acv.submitUserAuthClick), for: UIControlEvents.touchUpInside)
        backgroundView.addSubview(submitBtn)
            submitBtn.snp.makeConstraints { (make) in
                make.width.equalTo(kScreenW-60)
                make.height.equalTo(cellH)
                make.top.equalTo(btn4.snp.bottom).offset(30)
                make.centerX.equalTo(backgroundView.snp.centerX)
            }
        
    }
}
